package com.itheima.d06_set_treeset;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * 目标：了解TreeSet特点和底层结构
 */
public class Test {

    public static void main(String[] args) {
        //1.创建集合：数值型数据，默认按照数值大小进行升序排序
        TreeSet<Double> scores = new TreeSet<>();

        //2.添加数据
        scores.add(100.0);
        scores.add(90.0);
        scores.add(95.0);
        scores.add(95.0);
        scores.add(95.0);
        scores.add(85.0);
        scores.add(80.0);

        //3.打印结果
        System.out.println(scores);
        System.out.println("======");

        //1.创建集合：存储字符串，默认按照首字母字符进行升序排序
        TreeSet<String> names = new TreeSet<>();
        names.add("Zhangsan");
        names.add("lisi");
        names.add("axin");
        names.add("axin");
        names.add("axin");
        names.add("Wangwu");

        System.out.println( names);

        //1.创建集合，存储学生信息
        TreeSet<Student> students = new TreeSet<>(   (a,b) ->{
            if(b.getAge() == a.getAge()){
                return Double.compare(a.getScore(), b.getScore());
            }
            return b.getAge()- a.getAge();
        });

        //2.添加学生信息`
        students.add(new Student("狗哥", 18, 99.5));
        students.add(new Student("厂长", 19, 90));
        students.add(new Student("水子哥", 17, 80));
        students.add(new Student("圣枪哥", 18, 99.8));

        //3.打印结果
        students.forEach(System.out::println);
    }
}



































